package com.yp.lession.web.controller;

import com.yp.lession.entity.Temployees;
import com.yp.lession.services.TemployeesServices;
import com.yp.lession.services.impl.TemployeesServicesImpl;
import com.github.pagehelper.PageInfo;
import com.yp.lession.entity.Temployees;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: COS
 * @time: 2022/3/3 15:19
 * @description:
 */

@WebServlet("/emp")
public class TemployeesController extends HttpServlet {
    private TemployeesServices es = (TemployeesServices) new TemployeesServicesImpl();
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取前端提供的页码
        String pi = request.getParameter("pageNum");
        int pageNum = pi == null ? 0 : Integer.valueOf(pi);
        //调用业务层方法
        PageInfo<Temployees> empByPage = es.getEmpByPage(pageNum, 5);
        request.setAttribute("pi", empByPage);
        request.getRequestDispatcher("index.jsp").forward(request,response);
    }
}
